import java.io.IOException; // 需要导入 IOException 包
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-01-23
 * Time: 8:24
 */
import java.util.Random;//使用Random，需要导包
import java.util.Scanner;// 需要导入 util 包

public class TestDemo {
    public static void funNum(int n) {
        for (int i = 1; i <= n; i++) {
            int count = 0;//记录该数字是几位数
            int temp = i;
            //就是数字的位数
            while (temp != 0) {
                count++;
                temp /= 10;
            }
            temp = i;
            int sum = 0;
            //取出该数的每一位并进行幂运算
            while (temp != 0) {
                sum += Math.pow(temp % 10, count);
                temp /= 10;
            }
            //符号要求将该数字打印
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

    public static void main36(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        funNum(num);
    }



    public static int add(int x, int y) {
        return x + y;
    }

    public static double add(double x, double y, double z) {
        return x + y + z;
    }

    public static void main35(String[] args) {
        System.out.println("两个整数的和：" + add(20, 30));
        System.out.println("三个浮点数的和：" + add(10.5, 20.1, 32.6));
    }

    public static int max(int x, int y) {
        return x > y ? x : y;
    }

    public static double max(double x, double y) {
        return x > y ? x : y;
    }

    public static double max(double x, double y, int z) {
        return max(x, y) > z ? max(x, y) : z;
    }

    public static void main34(String[] args) {
        System.out.println("两个整数的最大值：" + max(10, 20));
        System.out.println("两个浮点数的最大值：" + max(10.5, 10.3));
        System.out.println("两个浮点数和一个整数的最大值：" + max(10.5, 10.3, 100));
    }


    public static int max3(int x, int y, int z) {
        return max2(x, y) > z ? max2(x, y) : z;
    }

    public static int max2(int x, int y) {
        return x > y ? x : y;
    }

    public static void main33(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println("两个数中的最大值：" + max2(a, b));
        System.out.println("三个数中的最大值：" + max3(a, b, 10));
    }

    public static void main32(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        System.out.println(ret);
    }


    public static void main31(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for (int i = 1; i <= num; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i + "*" + j + "=" + i * j + "  ");
            }
            System.out.println();
        }
    }



    public static int fun(int n){
        if(n<9){
            System.out.println(n);
        }
        return fun(n/10);
    }
    public static void main30(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        fun(num);
    }
    public static void main29(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        while (num!=0){
            System.out.println(num%10);
            num/=10;
        }
//            int a = num/100;
//            int b = num/10%10;
//            int c = num%10;
//        System.out.println(a+"，"+b+"，"+c);
    }

    public static void main28(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()){
            int n = scanner.nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i == j || j == n - 1 - i) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
        scanner.close();
    }
    public static void main27(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j || j == n - 1 - i) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
        scanner.close();
    }



    public static void main26(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int count = 0;
        while (num != 0) {
            num &= num - 1;
            count++;
        }
        System.out.println(count);
    }


    public static void main25(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = a % b; //18 % 24
        while (c != 0) {
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println("和最大公约数是：" + b);
    }


    public static void login() {
        Scanner scanner = new Scanner(System.in);
        int count = 3;
        String str = "123456";
        while (count != 0) {
            System.out.print("请输入密码：");
            String passWord = scanner.nextLine();
            if (passWord.equals(str)) {
                System.out.println("登录成功");
                break;
            } else {
                count--;
                System.out.println("密码错误" + "你还有" + count + "次机会");
            }
        }
    }

    public static void main24(String[] args) {
        login();
    }


    //计算两个整数的和
    public static int dadd(int x, int y) {
        return x + y;
    }

    //计算三个整数的和
    public static int dadd(int x, int y, int z) {
        return x + y + z;
    }

    //计算两个浮点数的和
    public static double dadd(double x, double y) {
        return x + y;
    }

    public static void main23(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(dadd(a, b));

        System.out.println(dadd(10, 20, 30));

        double c = 10.5;
        double d = 20.6;
        System.out.println(dadd(c, d));
    }

    public static void main22(String[] args) {
        int a = 10;
        int b = 20;
        print(a, b);
    }
    public static void print(int x, int y) {
        System.out.println("x = " + x + " y = " + y);
    }


    public static void Swap(int x, int y) {
        int temp = x;
        x = y;
        y = temp;
    }

    public static void main21(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前：" + "a的值：" + a + " b的值：" + b);
        Swap(a, b);
        System.out.println("交换前：" + "a的值：" + a + " b的值：" + b);
    }


    /**
     * 求某一个数的阶乘
     * @param n 传的数字
     * @return 5！ = 5*4*3*2*1
     */
    public static int fac(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }

    /**
     * 求一个数的阶乘之和
     * @param n 传的数字
     * @return 5! = 1! + 2! + 3! + 4! + 5!
     */
    public static int facSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }

    public static void main20(String[] args) {
        int retsum = facSum(5);
        System.out.println(retsum);
        System.out.println(facSum(10));
    }


    public static void main19(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("第一次调用方法之前");
        int ret = ad(a, b);
        System.out.println("第一次调用方法之后");
        System.out.println("ret = " + ret);
        System.out.println("第二次调用方法之前");
        ret = ad(30, 50);
        System.out.println("第二次调用方法之后");
        System.out.println("ret = " + ret);
    }

    public static int ad(int x, int y) {
        System.out.println("调用方法中 x = " + x + " y = " + y);
        return x + y;
    }


    /**
     * Add函数 ：计算两个整数的和
     * @param x：形参 x
     * @param y：形参 y
     * @return :两个整数相加后的值
     */
    public static int Add(int x, int y) {
        int sum = x + y;
        return sum;
    }
    //main方法（函数）
    public static void main18(String[] args) {
        int ret = Add(10, 25);
        System.out.println(ret);
        //System.out.println(Add(10,25));
    }


    public static void main17(String[] args) {
        double sum = 0.0;
        int flag = 1;
        for (int i = 1; i <= 100; i++) {
            sum += 1.0 / i * flag;
            flag = -flag;
        }
        System.out.println(sum);
    }


    public static void main16(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = a % b; // 18 % 24 = 6
        while (c != 0) {
            a = b;
            b = c;
            c = a % b;  //24 % 6
        }
        System.out.println(b);
    }

    public static void main15(String[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i + "*" + j + "=" + i * j + "  ");
            }
            System.out.println();
        }
    }

    public static void main14(String[] args) {
        for (int year = 1000; year <= 2000; year++) {
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                System.out.println(year + "是闰年");
            }
        }
//        for (int year = 1000; year <= 2000; year++) {
//            if (year % 100 != 0) {
//                if (year % 4 == 0) {
//                    System.out.println(year + "普通闰年");
//                }
//            } else if (year % 400 == 0) {
//                System.out.println(year + "世纪闰年");
//            }
//        }
    }


    public static void main13(String[] args) {
        int j = 2;
        //判断 2~n/2
        for (int i = 2; i <= 100; i++) {
            for (; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    break;
                }
            }
            if (j > Math.sqrt(i)) {
                System.out.println(i + "是素数");
            }
        }
    }

    public static void main12(String[] args) {
        //只需要判断 2~sqrt(n)
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int i = 0;
        //判断 2~n/2
        for (i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                System.out.println(num + "不是素数");
                break;
            }
        }
        if (i > Math.sqrt(num)) {
            System.out.println(num + "是素数");
        }
    }

    public static void main11(String[] args) {
        // n -> a*b  其中肯定有一个数字是小于等于 n/2
        //16  1*16  2*8 4*4 其中肯定有一个数字是小于等于 16/2
        //只需要判断 2~n/2

        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int i = 0;
        //判断 2~n/2
        for (i = 2; i <= num / 2; i++) {
            if (num % i == 0) {
                System.out.println(num + "不是素数");
                break;
            }
        }
        if (i > num / 2) {
            System.out.println(num + "是素数");
        }
    }


    public static void main10(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int i = 0;
        //判断 2 ~ num-1
        for (i = 2; i < num; i++) {
            if (num % i == 0) {
                System.out.println(num + "不是素数");
                break;
            }
        }
        if (i == num) {
            System.out.println(num + "是素数");
        }
    }



    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if (num > 0 && num < 18) {
            System.out.println("少年");
        } else if (num < 29) {
            System.out.println("青年");
        } else if (num < 56) {
            System.out.println("中年");
        } else {
            System.out.println("老年");
        }
    }


    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if (num > 0 && num < 18) {
            System.out.println("少年");
        } else if (num >= 18 && num < 29) {
            System.out.println("青年");
        } else if (num >= 29 && num < 56) {
            System.out.println("中年");
        } else {
            System.out.println("老年");
        }
    }


    public static void main7(String[] args) {
        Random random = new Random();
        int ran = random.nextInt(100) + 1;
        //random生成的随机数是左闭右开区间，输入100其实就是 0 到 99 --> [ 0 ~100),，如果+1就是1~100 [1~101)
        System.out.println("请输入你要猜的数字");
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int num = scanner.nextInt();
            if (num > ran) {
                System.out.println("你猜的数字太大了");
            } else if (num < ran) {
                System.out.println("你猜的数字太小了");
            } else {
                System.out.println("恭喜你，猜对了");
                break; //猜对了就跳出循环
            }
        }
    }

    public static void main6(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        System.out.println(str1);
    }

    public static void main5(String[] args) throws IOException {
        System.out.print("Enter a Char:");
        char i = (char) System.in.read();
        System.out.println("your char is :" + i);
    }

    public static void main4(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int num = 0;
        double sum = 0.0;
        while (sc.hasNextDouble()) {
            double ret = sc.nextDouble();
            sum += ret;
            num++;
        }
        System.out.println(sum);
        sc.close();
    }


    public static void main3(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("输入姓名：");
        String name = sc.next();
        System.out.print("输入年龄：");
        int age = sc.nextInt();
        System.out.print("输入成绩：");
        float score = sc.nextFloat();
        System.out.println("姓名：" + name + "\n年龄：" + age + "\n成绩：" + score);
        sc.close(); // 注意, 要记得调用关闭方法
    }



    public static void main2(String[] args) {
        try {
            System.out.print("Enter a Char:");
            char i = (char) System.in.read();
            System.out.println("your char is :" + i);
        } catch (IOException e) {
            System.out.println("exception");
        }
    }


    public static void main1(String[] args) {
        System.out.println("Hello World");
        int x = 10;
        System.out.printf("x=%d\n",x);
    }
}
